package com.world.superApp.utility;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class CommonUtil  {

	/*
	 * 获取流水号是 根据Type 获取 修改字典表是生成的自定义的KEY 也用获取流水号 设置为 999
	 */

	public static String DICTIONARY_KEY_STREAM_NO = "999";// 否

	/*
	 * 客户表中新建客户 是 客户 供应商 来往客户
	 */
	public static String CUSTOMER_TYPE_FLAG_0 = "false";// 否

	public static String CUSTOMER_TYPE_FLAG_1 = "true";// 是
	
	public static String IS_CUSTOMER = "is_customer";
	public static String IS_SUPPLIER = "is_supplier";
	public static String IS_CONTACT_COMPANY = "is_contact_company";

	// 好友分组 在DICTIONARY表中的dict_type
	public static String FRIEND_GROUP = "friend_group";

	// 是
	public static String _YES = "1";
	// 否
	public static String _NO = "0";
	
	
	/*openoffice configuration*/
	public static String TPM_PICNUMBER = "picnamber";
	public static String TPM_PICURL = "picurl";
	public static String TPM_ISSUCCESS = "issuccess";
	
	public static String typeList = "application/pdf;application/msword;application/msexcel;application/vnd.openxmlformats-officedocument.wordprocessingml.document;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.ms-powerpoint;application/vnd.openxmlformats-officedocument.presentationml.presentation;*.doc;*.docx;*.ppt;*.pptx;*.xls;*.xlsx;*.pdf;";
	public static boolean checkIsToCorvert(String type){
		if(null == type) return false;				
		return typeList.contains(type+";");
	}
	
	
	public static String gettype(String t){
		if(t.trim().equals("text")){
			return "varchar(500)";
		}
		if(t.trim().equals("number")){
			return "decimal(22,4)";
		}
		if(t.trim().equals("datetime")){
			return "datetime";
		}
		return "varchar(500)";
	}
	

	public static Boolean compareRuleResult(String resultScript,String param){
		Boolean rs = false;
		ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("js");
        resultScript = resultScript.replaceAll(":p\\d+:p", param);
        try {
        	rs = (Boolean)engine.eval(resultScript);
		} catch (ScriptException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rs;
	}
	
}
